package link.gpt.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import link.gpt.dao.EbookEntryDao;
import link.gpt.pojo.EbookEntry;
import link.gpt.service.EbookEntryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version V1.0A
 * @uthor gpt
 * @Project holiday_task
 * @Package link.gpt.service.impl
 * @Description: ${TODO}
 * @Date 2021/10/3 16:11
 */
@Service
public class EbookEntryServiceImpl implements EbookEntryService {

   @Autowired
   private EbookEntryDao ebookEntryDao;


   @Override
   public PageInfo<EbookEntry> findAllByCategoryIdAndPage(Integer categoryId, int num, int size) {
      PageHelper.startPage(num, size);
      List<EbookEntry> ebookEntryList = ebookEntryDao.findAllByCategoryIdAndPage(categoryId);
      PageInfo<EbookEntry> pageInfo = new PageInfo<>(ebookEntryList);
      return pageInfo;
   }

   @Override
   public EbookEntry findByBookId(Integer id) {
      return ebookEntryDao.findById(id);
   }

   @Override
   public int insertBook(EbookEntry ebookEntry) {
      return ebookEntryDao.insertSelective(ebookEntry);
   }

   @Override
   public int updateBook(EbookEntry ebookEntry) {
      return ebookEntryDao.updateByPrimaryKeySelective(ebookEntry);
   }

   @Override
   public int deleteBookById(Integer id) {
      return ebookEntryDao.deleteByPrimaryKey(id);
   }
}
